package org.wiztools.thegreatwall;

import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author arun
 */
public class ViewWallServlet extends HttpServlet {

    private static final Logger LOG = Logger.getLogger(ViewWallServlet.class.getName());

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException  {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
        LOG.info("View Wall Servlet: doGet()");
        final String wallName = req.getParameter("w");
        try {
            LOG.info("request wall name is " + wallName);
            Wall w = new MySQLOperations().getWallPosts(wallName);
            LOG.info("wall information: " + w);
            List<Post> post = w.getPost();
            for (Post p : post) {
                LOG.info("post: " + p);
            }

            req.setAttribute("wall", w);
            final RequestDispatcher rd = req.getRequestDispatcher("/wall.jsp");
            rd.forward(req, res);
        } catch (OperationException ex) {
            LOG.log(Level.SEVERE, null, ex);
        }
    }
}
